package com.tedu.ds.dept.controller;

import com.tedu.ds.dept.pojo.dto.DepartmentParam;
import com.tedu.ds.dept.pojo.dto.DepartmentQuery;
import com.tedu.ds.dept.service.DepartmentService;
import com.tedu.ds.base.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/department/")
@Api(tags = "部门模块")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @PostMapping("/select")
    @ApiOperation("查询功能")
    public JsonResult select(@RequestBody DepartmentQuery departmentQuery){
        return JsonResult.ok(departmentService.select(departmentQuery));
    }
    @PostMapping("/save")
    @ApiOperation("新增和更新功能")
    public JsonResult save(@RequestBody @Validated DepartmentParam departmentParam){
        departmentService.save(departmentParam);
        return JsonResult.ok();
    }

    @DeleteMapping("/deleteById/{id}")
    @ApiOperation("删除功能")
    public JsonResult deleteById(@PathVariable Integer id){
        departmentService.deleteById(id);
        return JsonResult.ok();
    }
}
